<template>
  <el-breadcrumb separator-class="el-icon-arrow-right">
    <el-breadcrumb-item v-for="level in levelList" :key="level">{{level}}</el-breadcrumb-item>
  </el-breadcrumb>
</template>

<script>
import Cookie from 'js-cookie'
import {NAVIGATION_DATA_ADMIN, NAVIGATION_DATA_CHECK, NAVIGATION_DATA_ENGINER} from '@/util/constant'

export default {
  name: 'breadcrumb',
  data () {
    return {
      levelList: []
    }
  },
  mounted () {
    this.levelList = []
  },
  methods: {
    getBreadcrumb: function () {
      // 读取角色，并根据角色判断使用哪个菜单栏
      const role = Cookie.get('role')
      let NAVIGATION_DATA = role === '系统管理员' ? NAVIGATION_DATA_ADMIN 
                          : role==='审核人员' ? NAVIGATION_DATA_CHECK : NAVIGATION_DATA_ENGINER
      // TODO o(n^3)
      this.levelList = []
      for (let i = 0; i < NAVIGATION_DATA.length; i++) {
        let level1name = NAVIGATION_DATA[i].name
        let level2 = NAVIGATION_DATA[i].child
        for (let j = 0; j < level2.length; j++) {
          let level2name = level2[j].name
          let level3 = level2[j].child
          for (let k = 0; k < level3.length; k++) {
            if (level3[k].name === this.$route.meta.title) {
              this.levelList.push(level1name)
              this.levelList.push(level2name)
              this.levelList.push(level3[k].name)
              break
            }
          }
        }
      }
    }
  },
  watch: {
    $route () {
      this.getBreadcrumb()
    }
  }
}
</script>

<style scoped>

</style>
